﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;
using WMI.NET.CIM;

namespace WMI.NET.ComputerSystemHardware.Printing
{
    /// <summary>
    /// 
    /// </summary>
    public class Win32_DriverForDevice : CIM_Dependency
    {

        private Win32_Printer _Antecedent;
        private Win32_PrinterDriver _Dependent;

        /// <summary>
        /// Reference to the Win32_Printer instance that represents the printer.
        /// </summary>
        public new Win32_Printer Antecedent { get { return _Antecedent; } }

        /// <summary>
        /// Reference to the Win32_PrinterDriver instance that represents the printer driver for the printer.
        /// </summary>
        public new Win32_PrinterDriver Dependent { get { return _Dependent; } }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_DriverForDevice(ManagementBaseObject mbo)
            : base(null) //TODO maybe null
        {
            _Antecedent = new Win32_Printer(mbo.ObjectQuery_WHERE("Win32_Printer", "Antecedent").Searcher().SingleMBO());
            _Dependent = new Win32_PrinterDriver(mbo.ObjectQuery_WHERE("Win32_PrinterDriver", "Dependent").Searcher().SingleMBO());

        }

    }


    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_DriverForDevices : Win32Collection<Win32_DriverForDevice>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_DriverForDevice> GetCollection()
        {
            List<Win32_DriverForDevice> tempCollection = new List<Win32_DriverForDevice>();

            foreach (var s in searcher.Get())
            {
                Win32_DriverForDevice tempListItem = new Win32_DriverForDevice(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_DriverForDevices() : base("SELECT * FROM Win32_DriverForDevice") { }

    }

}
